/*
 * wbh实习专用，其他人无权访问
 *Practice IntelligenceMajor YCHS 2022
 *努力不一定有回报
 */
package com.wbh.lawyermanager.dongao.controller;

import com.wbh.lawyermanager.dongao.entity.Lawyer;
import com.wbh.lawyermanager.dongao.service.LawyerService;
import com.wbh.lawyermanager.dongao.service.LawyerServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.xml.ws.RequestWrapper;
import java.util.List;

/**
 * @author wangbohong
 * @version 1.0
 * 律师控制器
 */
@Controller
public class LawyerController {
    @Autowired
    LawyerService lawyerService;

    @RequestMapping("/modify")
    public String modifyLawyer(Lawyer lawyer){
        lawyerService.modifyLawyer(lawyer);
        //return "../static/success";
        return "redirect:/show";
    }

    @RequestMapping("/getLawyer")
    public String getLawyerById(Model model,int lawyerid){
        Lawyer lawyer = lawyerService.findLawyerById(lawyerid);
        // 把查询得到的lawyer对象保存起来，传递到网页上
        model.addAttribute("lawyer", lawyer);
        return "../static/modifyLawyer";
    }

    @RequestMapping("/addLawyer")
    public String addLawyer(Lawyer lawyer){
        lawyerService.addLawyer(lawyer);
        return "../static/success";
    }
    @RequestMapping("/show")
    public String showLawyer(Model model){
        List<Lawyer> lawyerList = lawyerService.findLawyer();
        //把lawyerList传递到网上
        model.addAttribute("lawList",lawyerList);
        //displayLawyer代表网页
        return "../static/displayLawyer";
    }
    @RequestMapping("/delLawyer")
    public String deleteLawyer(int lawyerid){
        lawyerService.cancelLawyer(lawyerid);
        return "../static/success";
    }
}
